package BinaryTree;

import org.junit.Test;

import static MyUtils.MHUtils.*;
import static MyUtils.MHMoban.*;

public class 二叉树任意两点最大路径和124 {
    int resMax = Integer.MIN_VALUE;
    public int maxPathSum(TreeNode root) {
        back(root);
        return resMax;
    }
    private int back(TreeNode cur) {
        if(cur==null){
            return 0;
        }
        int L = back(cur.left);
        int R = back(cur.right);
        //全局 找最大：c c+L c+R c+L+R ,res
        int c = cur.val;
        resMax = max5(c,c+L,c+R,c+L+R, resMax);
        //return; 可以向上形成路径的
        return max3(c,c+L,c+R);
    }
}
